<template>
    <div class="app-container">
        <!-- 主页列表 -->
        <div class="listDiv" v-loading="tableLoading">
            <!-- table列表 -->
            <el-table
                :data="tableData"
                class="tableData"
                style="width: 100%">
                <el-table-column
                    prop="name"
                    label="部门"
                >
                </el-table-column>
                <el-table-column
                    prop="projectCount"
                    label="角色名称"
                >
                </el-table-column>
                <el-table-column
                    prop="doctorCount"
                    label="权限"
                >
                </el-table-column>
                <el-table-column
                    prop="tags"
                    label="数据范围"
                >
                </el-table-column>
                <el-table-column
                    label="状态"
                >
                    <template slot-scope="scope">
                        <el-switch
                        class="switchStyle"
                        v-model="scope.row.status"
                        @click.native="changeStatus(scope.row.id,'status',scope.row.status)"
                        active-color="#13ce66"
                        inactive-color="#eee"
                        :active-value="0"
                        :inactive-value="1">
                        </el-switch>
                    </template>
                </el-table-column>
                <el-table-column
                    fixed="right"
                    label="操作"
                    width="100"
                >
                <template slot-scope="scope">
                    <el-button type="text" @click="toRoutes('permissionsManageAdd',scope.row.id)" size="small">数据范围</el-button>
                </template>
                </el-table-column>
            </el-table>
            <!-- 分页 -->
            <div class="pagesCon">
                <div>
                    <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="listForm.pageNum"
                    :page-sizes="page_sizes"
                    :page-size="listForm.limit"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="page_totals">
                    </el-pagination>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import { listAdminPermissions} from '@/api/permissionsManage'
export default {
    name:"permissionsManageIndex",
    data(){
        return {
            tableLoading:true,
            date:"",
            value1:"",
            options:[{
                    value: '0',
                    label: '正常'
                }, {
                    value: '1',
                    label: '停用'
                }
            ],
            tableData: [],
            page_sizes:[10,30,50,100],
            page_totals:60,
            listForm:{
                pageNum: 1,
                pageSize:10
            },
        }
    },
    mounted(){
        this.getList(this.listForm)
    },
    methods:{
        //成功状态弹窗
        succStatus(txt){
            this.$message({
                message: txt+'成功',
                type: 'success'
            });
        },
        //失败状态弹窗
        errorStatus(txt){
            this.$message.error(txt+'失败');
        },
        //查询
        searchFn(){
            this.form.officeId = this.form.officeId+""
            // console.log(this.form)
            this.getList(this.form)
        },
        // 路由跳转
        toRoutes(e,userId) {
            let route = {name:e,query:{userId:userId}}
            this.$router.push(route)
        },
        //查询
        searchFn(){
            // console.log(this.form)
            // this.getList(this.form)
        },
        //列表数据获取
        getList(e){
            this.tableLoading = true
            let datas = e
            listAdminPermissions(datas).then(res => {
                console.log(res)
                if(!res.data.code){
                    // console.log(res)
                    this.tableData = res.data.data.list
                    this.page_totals = res.data.data.count
                }else{
                    this.$message.error("数据接口访问失败");
                }
                this.tableLoading = false
            })
            .catch(error =>{
                this.$message.error(error);
            })
        },
        //删除
        deleteFn(e){
            let datas = {
                id:e
            }
            this.$confirm('删除该条数据, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                deleteData(datas).then(res =>{
                    console.log(res)
                    if(!res.data.code){
                        this.succStatus("删除")
                        this.getList(this.listForm)
                    }else{
                        this.$message.error("数据接口访问失败");
                    }
                })
                .catch(error =>{
                    this.$message.error(error);
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                }); 
            });
        },
        //改变页面条数
        handleSizeChange(val) {
            this.listForm.pageNum = val
            this.getList(this.listForm)
        },
        //选择页数
        handleCurrentChange(val) {
            this.listForm.pageSize = val
            this.getList(this.listForm)
        },
    }
}
</script>
<style scoped>
/* 分页 */
.pagesCon{height: 40px;margin-top: 20px}
.pagesCon>div{float: right;}
</style>
